import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class SplashAlert extends Canvas
{
	private int width;
	private int height;
	private Image icon;
	private String title;
	private MenuManager mngr;
	
	public static final int OK = 0;
	public static final int WARNING = 1;
	public static final int ERROR = 2;
		
	public SplashAlert(MenuManager mgr, int type, String title)
	{
		this.width = this.getWidth();
		this.height = this.getHeight();
		this.title = title;
		this.mngr = mgr;
		
		try
		{
			switch(type)
			{
				case SplashAlert.WARNING:
					icon = Image.createImage("/warning_icon.png");
					break;
				case SplashAlert.ERROR:
					icon = Image.createImage("/error_icon.png");
					break;
				case SplashAlert.OK:
				default:
					icon = Image.createImage("/ok_icon.png");
			}
		}
		catch(Exception e)
		{
			icon = Image.createImage(1, 1);
		}
	}
	
	protected void keyReleased(int keyCode)
	{
		mngr.itemSelected(0);
	}
	
	public void paint(Graphics g)
	{
	
		g.setColor(mngr.getDefaultBGColor());
		g.fillRect(0,0, width, height);
		
		/* La oposit */
		g.setColor(0x00FFFFFF - g.getColor());
		
		/* Mini map */
		g.drawString("( pritistni katerokoli tipko )", width / 2, 20, Graphics.BASELINE | Graphics.HCENTER);

		/* Draw current in the middle of screen */
		g.drawImage(this.icon, width / 2, height / 2, Graphics.VCENTER | Graphics.HCENTER);
		
		/* Draw description below */
		g.drawString(title , width / 2, height - 20, Graphics.BASELINE | Graphics.HCENTER );	
	}
}
